package com.shortlink.server.remote;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.shortlink.server.remote.dto.IpDetailReqDTO;
import com.shortlink.server.remote.dto.IpDetailRespDTO;
import org.springframework.stereotype.Component;

import static com.shortlink.server.constant.APIUrlConstant.IP_DETAIL_URL;

/**
 * 远程api服务
 *
 * @author wp
 */
@Component
public class ApiRemoteService {
    public String getIpLocale(String ip) {
        IpDetailReqDTO ipDetailReq = new IpDetailReqDTO(ip);
        String jsonStr = HttpUtil.get(IP_DETAIL_URL, BeanUtil.beanToMap(ipDetailReq));
        IpDetailRespDTO ipDetailResp = JSONUtil.toBean(jsonStr, IpDetailRespDTO.class);
        return ipDetailResp.getPro();
    }
}
